//
//  WMOpenProtocolViewController.m
//  DSBet
//
//  Created by hwm on 2018/5/23.
//  Copyright © 2018年 Bill. All rights reserved.
//

#import "WMOpenProtocolViewController.h"
#import <WebKit/WebKit.h>

@interface WMOpenProtocolViewController () <WKUIDelegate, WKNavigationDelegate>

@property (nonatomic, strong) WKWebView *wkWebView;
@property (nonatomic, strong) NSString *htlmName;

@end

@implementation WMOpenProtocolViewController

+ (instancetype)openProtocolWithHtml:(NSString *)htlmName
{
    WMOpenProtocolViewController *vc = [WMOpenProtocolViewController new];
    vc.htlmName = htlmName;
    [vc setUpInfoData];
    return vc;
}

- (void)setUpInfoData {
    [self initWkWebView];
}

- (void)initWkWebView {
    if (!_wkWebView) {
        
        _wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        _wkWebView.navigationDelegate = self;
        _wkWebView.UIDelegate = self;
        [self.view addSubview:_wkWebView];
    }
    NSString *path = [[NSBundle mainBundle] pathForResource:self.htlmName ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest* request = [NSURLRequest requestWithURL:url];
    [_wkWebView loadRequest:request];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSString *path = [[NSBundle mainBundle] pathForResource:self.htlmName ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest* request = [NSURLRequest requestWithURL:url];
    [_wkWebView loadRequest:request];
}

@end
